home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2915 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  54 lines

  1. Path: nic.wat.hookup.net!news
  2. From: xenon@the-fix.sos.on.ca
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Question!@#!
  5. Date: Tue, 23 Jan 1996 22:42:08 GMT
  6. Organization: HookUp Communication Corporation, Waterloo, Ontario, CANADA
  7. Message-ID: <4e3p30$off@nic.wat.hookup.net>
  8. References: <4dcejq$2un@venus.senecac.on.ca>
  9. NNTP-Posting-Host: slip5.sos.on.ca
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. cweselak@learn.senecac.on.ca (Christian Weselak) wrote:
  13.  
  14.  
  15. >I have a very Simple question.. well, it should be simple for 'alot' of 
  16. >you reading this newsgroup..
  17.  
  18. >anyways.
  19.  
  20. >I have created a program that asks THE users for his name, then writes it 
  21. >to a file, the file is called name.txt..
  22.  
  23. >Evertime this program is executed, the file name.txt get's overwritten.
  24.  
  25. >How can i keep this file, name.txt, so that i can eventually have a 
  26. >listing of all users who ran my program???
  27.  
  28. >Appreciated..
  29.  
  30. Hi.  Your problem lies in the mode your using for fopen().  Your most
  31. likely using the mode "w" instead of "a"  Try this:
  32.  
  33. include <stdio.h>
  34. include <conio.h>
  35.  
  36. main()
  37. {
  38.     FILE *fp;
  39.     char name[20];
  40.     puts("Enter your name: \n");
  41.     gets(name);
  42.     fp=fopen("names.txt","a")     /* append instead of write..should test 
  43.                      for occurrence of error from fopen :>*/
  44.     fprintf(fp,"%s",name);
  45.     fclose(fp);
  46. }
  47.  
  48. Hope this helps...
  49.  
  50. xenon@sos.on.ca
  51.  
  52.  
  53.  
  54.